<?php

/**
 * This is the model class for table "news".
 *
 * The followings are the available columns in table 'news':
 * @property string $id
 * @property string $cat_id
 * @property string $title
 * @property string $desc
 * @property string $content
 * @property string $created_time
 * @property string $creator_id
 * @property string $last_updated_time
 * @property string $last_updated_by
 * @property string $view_count
 * @property integer $special
 * @property string $cvr_img
 * @property string $index
 *
 * The followings are the available model relations:
 * @property ArticleImage $id0
 * @property ArticleImage $cvrImg
 * @property Category $cat
 */
class News extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return News the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'news';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cat_id, title, desc, content, created_time, creator_id, last_updated_time, last_updated_by', 'required'),
			array('special', 'numerical', 'integerOnly'=>true),
			array('cat_id, creator_id, last_updated_by, view_count, index', 'length', 'max'=>11),
			array('cvr_img', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, cat_id, title, desc, content, created_time, creator_id, last_updated_time, last_updated_by, view_count, special, cvr_img, index', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'id0' => array(self::BELONGS_TO, 'ArticleImage', 'id'),
			'cvrImg' => array(self::BELONGS_TO, 'ArticleImage', 'cvr_img'),
			'cat' => array(self::BELONGS_TO, 'Category', 'cat_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cat_id' => 'Cat',
			'title' => 'Title',
			'desc' => 'Desc',
			'content' => 'Content',
			'created_time' => 'Created Time',
			'creator_id' => 'Creator',
			'last_updated_time' => 'Last Updated Time',
			'last_updated_by' => 'Last Updated By',
			'view_count' => 'View Count',
			'special' => 'Special',
			'cvr_img' => 'Cvr Img',
			'index' => 'Index',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('cat_id',$this->cat_id,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('desc',$this->desc,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('created_time',$this->created_time,true);
		$criteria->compare('creator_id',$this->creator_id,true);
		$criteria->compare('last_updated_time',$this->last_updated_time,true);
		$criteria->compare('last_updated_by',$this->last_updated_by,true);
		$criteria->compare('view_count',$this->view_count,true);
		$criteria->compare('special',$this->special);
		$criteria->compare('cvr_img',$this->cvr_img,true);
		$criteria->compare('index',$this->index,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}